<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of imagem_model
 *
 * @author souzadavi
 */
class Imagem_model extends CI_Model {

    //put your code here

    public function __construct() {
        parent::__construct();
        $this->load->config('parametros');
    }
    
    public function get($_id) {
        $this->db->where('id', trim($_id));
        $query = $this->db->get($this->config->item('dbCliente') . $this->config->item('tblImagens'));
        if ($query->num_rows() > 0) {
            return $query->row();
        } else {
            return NULL;
        }
    }

    public function consultar($_id) {
        $this->db->where('id', $_id);
        $query = $this->db->get($this->config->item('dbCliente') . $this->config->item('tblImagens'));
        if ($query->num_rows() > 0) {
            return $query->result();
        } else {
            return NULL;
        }
    }

    public function consultar_total() {
        $query = $this->db->get($this->config->item('dbCliente') . $this->config->item('tblImagens'));
        if ($query->num_rows() > 0) {
            return $query->result();
        } else {
            return NULL;
        }
    }

    public function cadastrar($_dados = array()) {
        $this->db->set($_dados);
        $this->db->insert($this->config->item('dbCliente') . $this->config->item('tblImagens'));
        if ($this->db->affected_rows() > 0) {
            return $this->db->insert_id();
        } else {
            return NULL;
        }
    }

    public function alterar($_id, $_dados = array()) {
        $this->db->where('id', $_id);
        $this->db->set($_dados);
        $this->db->update($this->config->item('dbCliente') . $this->config->item('tblImagens'));
        if ($this->db->affected_rows() > 0) {
            return $_id;
        } else {
            return NULL;
        }
    }

    public function excluir($_id) {
        $this->db->where('id', $_id);
        $this->db->delete($this->config->item('dbCliente') . $this->config->item('tblImagens'));
        if ($this->db->affected_rows() > 0) {
            return TRUE;
        } else {
            return NULL;
        }
    }

}